﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace Lucilla.Framework.Web.Builders.SlickGrid
{
    public class SlickGridBuilder
    {
        private IList<Column> Columns;


        public SlickGridBuilder()
        {
            Columns = new List<Column>();
        }

        public SlickGridBuilder AddColumn(Column column)
        {
            Columns.Add(column);
            return this;
        }

        public string GetColumnsSource()
        {
            return SerializeData(Columns);
        }

        protected string SerializeData(object o)
        {
            return JsonConvert.SerializeObject(o, 
                Formatting.Indented,
                new JsonSerializerSettings
                    {
                        DefaultValueHandling = DefaultValueHandling.Ignore,
                        NullValueHandling = NullValueHandling.Ignore,
                        ContractResolver = new UnderscoreCamelCasePropertyNamesContractResolver()
                    }
            );
        }
    }
}
